﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.HtmlControls;
using EPiServer;
using EPiServer.Core.PropertySettings;
using EPiServer.Editor.TinyMCE;
using EPiServer.Web.PropertyControls;

namespace TemplateFoundation.UI.WebControls
{
    /// <summary>
    /// Rich-text editor to use for customized user interfaces inside the EPiServer UI
    /// </summary>
    public class Editor : EPiServer.Editor.TinyMCE.Editor
    {
        /// <summary>
        /// Instantiates a new Editor control with basic default settings
        /// </summary>
        public Editor()
        {
            // Get default editor settings
            PropertySettingsWrapper defaultSettings = new PropertySettingsRepository().GetDefault(typeof(TinyMCESettings));

            // Set toolbars
            PropertySettings = (TinyMCESettings)defaultSettings.PropertySettings;

            PropertySettings.ToolbarRows.Clear();

            PropertySettings.ToolbarRows.Add(new ToolbarRow(new [] {
            "epilink", "unlink", "anchor", "image", "media", "epidynamiccontent", "epiquote", "separator", "pastetext", "pasteword", "separator", "separator", "cleanup", "code", "visualaid", "fullscreen" }));

            PropertySettings.ToolbarRows.Add(new ToolbarRow(new[] { 
            "bold", "italic", "underline", "separator", "justifyleft", "justifycenter", "justifyright", "separator", "bullist", "numlist", "formatselect" }));

            Width = 460;
            Height = 200;
        }

        /// <summary>
        /// Gets or sets a comma-separated list of stylesheet links for editor content
        /// </summary>
        public string ContentCssFilePaths
        {
            get
            {
                return (string)InitOptions["content_css"];
            }
            set
            {
                InitOptions["content_css"] = value;
            }
        }
    }
}
